#include "StdAfx.h"
#include "CircuitRectangle.h"


CCircuitRectangle::CCircuitRectangle(void)
{
	m_dblStartPosX = 0;
	m_dblStartPosY = 0;
	m_dblEndPosX = 0;
	m_dblEndPosY = 0;
	m_dblBorderWidth = 0;
	m_dblBorderColor[0] = 0;
	m_dblBorderColor[1] = 0;
	m_dblBorderColor[2] = 0;
	m_dblFillColor[0] = 0;
	m_dblFillColor[1] = 0;
	m_dblFillColor[2] = 0;
	m_bSelected = false;
	m_bIsFill = false;
	m_linePattern = SOLID_LINE;
}

CCircuitRectangle::CCircuitRectangle(const CCircuitRectangle *pEntityObj)
	: CCircuitUnit(pEntityObj)
{
	m_dblStartPosX = pEntityObj->GetStartPosX();
	m_dblStartPosY = pEntityObj->GetStartPosY();
	m_dblEndPosX = pEntityObj->GetEndPosX();
	m_dblEndPosY = pEntityObj->GetEndPosY();
	m_dblBorderWidth = pEntityObj->GetBorderWidth();
	m_dblBorderColor[0] = pEntityObj->GetBorderColorR();
	m_dblBorderColor[1] = pEntityObj->GetBorderColorG();
	m_dblBorderColor[2] = pEntityObj->GetBorderColorB();
	m_dblFillColor[0] = pEntityObj->GetFillColorR();
	m_dblFillColor[1] = pEntityObj->GetFillColorG();
	m_dblFillColor[2] = pEntityObj->GetFillColorB();
	m_bSelected = pEntityObj->IsSelect();
	m_bIsFill = pEntityObj->IsFill();
	m_linePattern = pEntityObj->GetLinePattern();
}

CCircuitRectangle::CCircuitRectangle(CICircuit *pParentEnt)
	: CCircuitUnit(pParentEnt)
{
	m_dblStartPosX = 0;
	m_dblStartPosY = 0;
	m_dblEndPosX = 0;
	m_dblEndPosY = 0;
	m_dblBorderWidth = 0;
	m_dblBorderColor[0] = 0;
	m_dblBorderColor[1] = 0;
	m_dblBorderColor[2] = 0;
	m_dblFillColor[0] = 0;
	m_dblFillColor[1] = 0;
	m_dblFillColor[2] = 0;
	m_bSelected = false;
	m_bIsFill = false;
	m_linePattern = SOLID_LINE;
}

CCircuitRectangle::~CCircuitRectangle(void)
{
	Clear();
}

void CCircuitRectangle::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		ar << m_dblStartPosX;
		ar << m_dblStartPosY;
		ar << m_dblEndPosX;
		ar << m_dblEndPosY;
		ar << m_dblBorderWidth;
		ar << m_dblBorderColor[0];
		ar << m_dblBorderColor[1];
		ar << m_dblBorderColor[2];
		ar << m_dblFillColor[0];
		ar << m_dblFillColor[1];
		ar << m_dblFillColor[2];
		ar << m_bSelected;
		ar << m_bIsFill;
		ar << m_linePattern;
	}
	else
	{
		ar >> m_dblStartPosX;
		ar >> m_dblStartPosY;
		ar >> m_dblEndPosX;
		ar >> m_dblEndPosY;
		ar >> m_dblBorderWidth;
		ar >> m_dblBorderColor[0];
		ar >> m_dblBorderColor[1];
		ar >> m_dblBorderColor[2];
		ar >> m_dblFillColor[0];
		ar >> m_dblFillColor[1];
		ar >> m_dblFillColor[2];
		ar >> m_bSelected;
		ar >> m_bIsFill;
		
		if ( CObj::m_lFileVersion >= 118 )
		{
			int nLinePatt(0);
			ar >> nLinePatt;
			m_linePattern = (eLinePattern)nLinePatt;
		}
	}

	CCircuitUnit::Serialize(ar);
}

CObj *CCircuitRectangle::Clone() const
{
	return new CCircuitRectangle(this);
}

void CCircuitRectangle::Transform(const CMatrix transf)
{

}

bool CCircuitRectangle::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return CCircuitUnit::GetBox(dblLeft, dblBottom, dblRight, dblTop);
}

void CCircuitRectangle::Clear()
{

}

void CCircuitRectangle::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CCircuitRectangle::DeleteDisplayObj(long lLayerId)
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}

CDisplayObj *CCircuitRectangle::CreateDisplayObj(long lLayerId)
{
	CCircuitRectangleDisObj *pRectDis = new CCircuitRectangleDisObj(this);
	pRectDis->SetLayerId(lLayerId);
	return pRectDis;
}

void CCircuitRectangle::CalcBox()
{
	m_minX = min(m_dblStartPosX, m_dblEndPosX);
	m_minY = min(m_dblStartPosY, m_dblEndPosY);
	m_maxX = max(m_dblStartPosX, m_dblEndPosX);
	m_maxY = max(m_dblStartPosY, m_dblEndPosY);
}

eCircuitUnitEntType CCircuitRectangle::GetUnitType() const
{
	return CIRCUIT_RECT;
}

eLinePattern CCircuitRectangle::GetLinePattern() const
{
	return m_linePattern;
}

double CCircuitRectangle::GetStartPosX() const
{
	return m_dblStartPosX;
}

double CCircuitRectangle::GetStartPosY() const
{
	return m_dblStartPosY;
}

double CCircuitRectangle::GetEndPosX() const
{
	return m_dblEndPosX;
}

double CCircuitRectangle::GetEndPosY() const
{
	return m_dblEndPosY;
}

double CCircuitRectangle::GetBorderWidth() const
{
	return m_dblBorderWidth;
}

double CCircuitRectangle::GetBorderColorR() const
{
	return m_dblBorderColor[0];
}

double CCircuitRectangle::GetBorderColorG() const
{
	return m_dblBorderColor[1];
}

double CCircuitRectangle::GetBorderColorB() const
{
	return m_dblBorderColor[2];
}

bool CCircuitRectangle::IsSelect() const
{
	return m_bSelected;
}

bool CCircuitRectangle::IsFill() const
{
	return m_bIsFill;
}

double CCircuitRectangle::GetFillColorR() const
{
	return m_dblFillColor[0];
}

double CCircuitRectangle::GetFillColorG() const
{
	return m_dblFillColor[1];
}

double CCircuitRectangle::GetFillColorB() const
{
	return m_dblFillColor[2];
}

void CCircuitRectangle::SetLinePattern(eLinePattern ePatn )
{
	m_linePattern = ePatn;
}

void CCircuitRectangle::SetStartPosX(double posX)
{
	m_dblStartPosX = posX;
}

void CCircuitRectangle::SetStartPosY(double posY)
{
	m_dblStartPosY = posY;
}

void CCircuitRectangle::SetEndPosX(double posX) 
{
	m_dblEndPosX = posX;
}

void CCircuitRectangle::SetEndPosY(double posY)
{
	m_dblEndPosY = posY;
}

void CCircuitRectangle::SetBorderWidth(double dblWidth)
{
	m_dblBorderWidth = dblWidth;
}

void CCircuitRectangle::SetBorderColorR(double colR)
{
	m_dblBorderColor[0] = colR;
}

void CCircuitRectangle::SetBorderColorG(double colG)
{
	m_dblBorderColor[1] = colG;
}

void CCircuitRectangle::SetBorderColorB(double colB)
{
	m_dblBorderColor[2] = colB;
}

void CCircuitRectangle::SetSelect(bool bFlag)
{
	m_bSelected = bFlag;
}

void CCircuitRectangle::SetFill(bool bFlag)
{
	m_bIsFill = bFlag;
}

void CCircuitRectangle::SetFillColorR(double colR)
{
	m_dblFillColor[0] = colR;
}

void CCircuitRectangle::SetFillColorG(double colG)
{
	m_dblFillColor[1] = colG;
}

void CCircuitRectangle::SetFillColorB(double colB)
{
	m_dblFillColor[2] = colB;
}